import com.imooc.spring.jdbc.dao.EmployeeDao;
import com.imooc.spring.jdbc.entity.Employee;
import com.imooc.spring.jdbc.service.EmployeeService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.Date;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class JdbcTemplateTestor {
    @Resource
    private EmployeeDao employeeDao;
    @Resource
    private EmployeeService employeeService;

    @Test
    public void testFindById() {
        Employee employee = employeeDao.findById(3308);
        System.out.println(employee);
    }
    @Test
    public void testFindByDname() {
        System.out.println(employeeDao.findbyDname("市场部"));
    }
    @Test
    public void testFindMapByDname() {
        System.out.println(employeeDao.findMapByDname("市场部"));
    }
    @Test
    public void testInsert() {
        Employee employee = new Employee();
        employee.setEno(3309);
        employee.setEname("小王");
        employee.setSalary(10000.0f);
        employee.setDname("市场部");
        employee.setHireDate(new Date());
        employeeDao.insert(employee);
    }
    @Test
    public void testUpdate() {
        Employee employee = employeeDao.findById(3309);
        employee.setSalary(employee.getSalary() + 1000.0f);
        int num = employeeDao.update(employee);
        System.out.println("本地更新" + num+ "条数据");
    }
    @Test
    public void testDelete() {
        int count = employeeDao.delete(3309);
        System.out.println("删除了" + count + "条数据");
    }
    @Test
    public void testBatchImport() {
        employeeService.batchImport();
        System.out.println("批量导入完成");
    }
    @Test
    public void testStartImportJob() {
        employeeService.startImportJob();
        System.out.println("批量导入完成");
    }
}
